
<!DOCTYPE HTML>
<html lang="cn" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>webpack · 前端学习笔记</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="chengdaohua">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-anchors/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-toggle-chapters/toggle.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-advanced-emoji/emoji-website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    
    <link rel="prev" href="../websocket/websocket.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://chengdaohua.gitee.io/remarkbook/" target="_blank" class="custom-link">Home</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../vue/">
            
                <a href="../vue/">
            
                    
                    vue 学习
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../vue/start.html">
            
                <a href="../vue/start.html">
            
                    
                    原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../vue/mokuaihua.html">
            
                <a href="../vue/mokuaihua.html">
            
                    
                    模块化和组件化开发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../vue/huakucha.html">
            
                <a href="../vue/huakucha.html">
            
                    
                    花裤衩项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../vue/chushihua.html">
            
                <a href="../vue/chushihua.html">
            
                    
                    项目初始化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../vue/guifan.html">
            
                <a href="../vue/guifan.html">
            
                    
                    代码规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../js/jsReadme.html">
            
                <a href="../js/jsReadme.html">
            
                    
                    javaScript
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../js/array.html">
            
                <a href="../js/array.html">
            
                    
                    数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../js/object.html">
            
                <a href="../js/object.html">
            
                    
                    对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../js/function.html">
            
                <a href="../js/function.html">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../js/string.html">
            
                <a href="../js/string.html">
            
                    
                    字符串
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../review/project.html">
            
                <a href="../review/project.html">
            
                    
                    review
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../review/CodeReview.html">
            
                <a href="../review/CodeReview.html">
            
                    
                    CoderReview
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../node/简介.html">
            
                <a href="../node/简介.html">
            
                    
                    node
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../node/简介.html">
            
                <a href="../node/简介.html">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../node/express.html">
            
                <a href="../node/express.html">
            
                    
                    express
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../ts/ts.html">
            
                <a href="../ts/ts.html">
            
                    
                    ts
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../websocket/websocket.html">
            
                <a href="../websocket/websocket.html">
            
                    
                    websocket
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.8" data-path="webpack.html">
            
                <a href="webpack.html">
            
                    
                    webpack
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >webpack</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x5B89;&#x88C5;"><a name="&#x5B89;&#x88C5;" class="plugin-anchor" href="#&#x5B89;&#x88C5;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5B89;&#x88C5;</h1>
<pre><code class="lang-bash"><span class="hljs-comment"># &#x5B89;&#x88C5;webpack &#x547D;&#x4EE4;&#x884C;&#x5DE5;&#x5177;</span>
npm i -g webpack

<span class="hljs-comment"># &#x7F16;&#x5199;&#x914D;&#x7F6E;</span>
&#x9ED8;&#x8BA4;&#xFF1A;webpack.config.js
&#x6539;&#x4E86;&#xFF1A;webpack --config xxxx

<span class="hljs-comment"># &#x8FD0;&#x884C;</span>
webpack --config webpack.config.js
</code></pre>
<h1 id="es6-&#x6A21;&#x5757;&#x5316;"><a name="es6-&#x6A21;&#x5757;&#x5316;" class="plugin-anchor" href="#es6-&#x6A21;&#x5757;&#x5316;"><i class="fa fa-link" aria-hidden="true"></i></a>ES6 &#x6A21;&#x5757;&#x5316;</h1>
<pre><code class="lang-bash"><span class="hljs-comment"># &#x4F5C;&#x4E3A;&#x6A21;&#x5757;&#x672C;&#x8EAB;&#x88AB;&#x8F93;&#x51FA;</span>
<span class="hljs-built_in">export</span> default xxx;
import xxx from <span class="hljs-string">&apos;...&apos;</span>;

<span class="hljs-comment"># &#x8F93;&#x51FA;&#x6A21;&#x5757;&#x7684;&#x4E1C;&#x897F;</span>
<span class="hljs-built_in">export</span> <span class="hljs-built_in">let</span> a=12,b=5;
import {a,b} from <span class="hljs-string">&apos;...&apos;</span>;
</code></pre>
<h1 id="webpack-&#x57FA;&#x672C;&#x914D;&#x7F6E;"><a name="webpack-&#x57FA;&#x672C;&#x914D;&#x7F6E;" class="plugin-anchor" href="#webpack-&#x57FA;&#x672C;&#x914D;&#x7F6E;"><i class="fa fa-link" aria-hidden="true"></i></a>webpack &#x57FA;&#x672C;&#x914D;&#x7F6E;</h1>
<pre><code class="lang-Javascript"># &#x5355;&#x5165;&#x53E3;
module.exports={
  entry: &apos;&#x6587;&#x4EF6;&#x540D;&apos;,
  output: {
    path: &apos;&#x7ED3;&#x679C;&#x76EE;&#x5F55;&apos;,
    filename: &apos;&#x7ED3;&#x679C;&#x6587;&#x4EF6;&#x540D;&apos;
  }
};

# &#x591A;&#x5165;&#x53E3;
entry: {
  &#x540D;&#x5B57;: &apos;&#x5165;&#x53E3;&#x6587;&#x4EF6;&#x5730;&#x5740;&apos;,
  ...
},
output: {
  path: xxx,
  filename: &apos;...[name]...&apos;
}
</code></pre>
<h1 id="dev-server-&#x5F00;&#x53D1;&#x670D;&#x52A1;&#x5668;"><a name="dev-server-&#x5F00;&#x53D1;&#x670D;&#x52A1;&#x5668;" class="plugin-anchor" href="#dev-server-&#x5F00;&#x53D1;&#x670D;&#x52A1;&#x5668;"><i class="fa fa-link" aria-hidden="true"></i></a>dev-server &#x5F00;&#x53D1;&#x670D;&#x52A1;&#x5668;</h1>
<pre><code class="lang-javascript"># &#x5B89;&#x88C5;  &#x4E0D;&#x63A8;&#x8350;&#x5168;&#x5C40;&#x5B89;&#x88C5; &#x63A8;&#x8350;&#x672C;&#x5730;&#x5B89;&#x88C5; 1&#x7ECF;&#x5E38;&#x66F4;&#x65B0; 2&#x5BF9;&#x4E0D;&#x540C;&#x7684;&#x9879;&#x76EE;&#x9700;&#x8981;&#x8FDB;&#x884C;&#x5FAE;&#x8C03;

# &#x63D0;&#x4F9B;&#x547D;&#x4EE4;&#x884C;&#x5DE5;&#x5177;
webpack-cli
# webpack &#x6838;&#x5FC3;&#x5E93;
webpack
#
webpack-dev-server
cnpm i webpack webpack-cli webpack-dev-server -D

# package.json
# inline/iframe &#x914D;&#x7F6E; iframe&#x6A21;&#x5F0F;&#x548C;inline&#x6A21;&#x5F0F;
# watch &#x76D1;&#x542C;&#x9759;&#x6001;&#x8D44;&#x6E90;&#x81EA;&#x52A8;&#x70ED;&#x66F4;&#x65B0;
&quot;scripts&quot;:{
  &quot;start&quot;: &quot;webpack-dev-server --watch --inline --config webpack.config.js&quot;
}
</code></pre>
<pre><code class="lang-Javascript"><span class="hljs-keyword">const</span> pathlib=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;path&apos;</span>)
<span class="hljs-keyword">const</span> Webpack=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;webpack&apos;</span>)

<span class="hljs-built_in">module</span>.exports={
  mode: <span class="hljs-string">&apos;development&apos;</span>  <span class="hljs-comment">// &#x751F;&#x4EA7;&#x6216;&#x5F00;&#x53D1; &#x5F71;&#x54CD;&#x5E93;&#x7684;&#x8868;&#x73B0;</span>
  entry: <span class="hljs-string">&apos;./src/index&apos;</span>,
  output: {
    path: pathlib.resolve(<span class="hljs-string">&apos;dest&apos;</span>),
    filename: <span class="hljs-string">&apos;bundle.js&apos;</span>
  },
  plugins:[ <span class="hljs-comment">// &#x63D2;&#x4EF6;</span>
    <span class="hljs-keyword">new</span> Webpack.HotModuleReplacementPlugin() <span class="hljs-comment">// &#x70ED;&#x6A21;&#x5757;&#x66F4;&#x65B0;&#x63D2;&#x4EF6;&#xFF08;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4E0D;&#x4F1A;&#x81EA;&#x52A8;&#x66F4;&#x65B0;&#xFF09;</span>
  ],
  <span class="hljs-built_in">module</span>:{ <span class="hljs-comment">// 90%&#x7684;loade</span>
    rules: [
      {
        test: <span class="hljs-regexp">/\.js$/</span>,
        exclude:  <span class="hljs-regexp">/node_modules/</span> <span class="hljs-comment">// &#x6392;&#x9664;&#x90A3;&#x4E9B;&#x6587;&#x4EF6;</span>
        use: {
          loader: <span class="hljs-string">&apos;babel-loader&apos;</span>,
          options: {  <span class="hljs-comment">// loader &#x914D;&#x7F6E;</span>
            presets: [<span class="hljs-string">&apos;env&apos;</span>]
          }
        }
      } <span class="hljs-comment">// test &#x68C0;&#x6D4B;&#x6587;&#x4EF6;&#x540D; use &#x7528;&#x54EA;&#x4E2A;loader&#x5904;&#x7406;</span>
    ]
  }
  devServer: {
    contentBase: pathlib.resolve(<span class="hljs-string">&apos;static&apos;</span>), <span class="hljs-comment">// &#x5185;&#x5BB9;&#x6839;&#x76EE;&#x5F55;&#xFF08;&#x9759;&#x6001;&#x6587;&#x4EF6;&#xFF09;</span>
    port: <span class="hljs-number">8090</span>, <span class="hljs-comment">// &#x4E0D;&#x4F20;&#x9ED8;&#x8BA4;8080</span>
    hot: <span class="hljs-literal">true</span>,  <span class="hljs-comment">// &#x70ED;&#x66F4;&#x65B0;</span>
    historyApiFallback: <span class="hljs-literal">true</span> <span class="hljs-comment">// 404&#x90FD;&#x4F1A;&#x56DE;&#x9000;&#x8BBF;&#x95EE;index.html</span>
  }
}
</code></pre>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; wml 2019 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2020-05-22 14:08:23
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../websocket/websocket.html" class="navigation navigation-prev navigation-unique" aria-label="Previous page: websocket">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"webpack","level":"1.8","depth":1,"previous":{"title":"websocket","level":"1.7","depth":1,"path":"category/websocket/websocket.md","ref":"category/websocket/websocket.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-lunr","anchors","sitemap-general","toggle-chapters","expandable-chapters","splitter","edit-link","advanced-emoji","tbfed-pagefooter"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy wml 2019","modify_label":"该文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"github":{"url":"https://gitee.com/chengdaohua/remarkBook"},"simple-page-toc":{"maxDepth":3,"skipFirstH1":false},"splitter":{},"search-pro":{"cutWordLib":"nodejieba","defineWord":["gitbook-use"]},"search":{},"donate":{"wechat":"","alipay":"","title":"","button":"赏","alipayText":"支付宝打赏","wechatText":"微信打赏"},"sitemap-general":{"prefix":"https://chengdaohua.gitee.io/remarkbook/"},"changyan":{"appid":"cytowLiqM","conf":"the conf in the code generate by changyan"},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"sitemap":{"hostname":"https://wmlhub.gitee.io/gitbook/"},"baidu":{"token":"084b900a1e26f6bae60e09d18e3aa455"},"advanced-emoji":{"embedEmojis":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":true,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"edit-link":{"label":"Edit This Page","base":"https://gitee.com/chengdaohua/remarkBook"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"anchors":{},"toggle-chapters":{},"expandable-chapters":{}},"theme":"default","author":"chengdaohua","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"前端学习笔记","language":"cn","links":{"sidebar":{"Home":"https://chengdaohua.gitee.io/remarkbook/"}},"gitbook":"3.2.3","description":"记录日常学习总结"},"file":{"path":"category/webpack/webpack.md","mtime":"2020-05-22T06:08:23.528Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-05-22T06:18:21.707Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-toggle-chapters/toggle.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-edit-link/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

